﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace Brain
{
    public class TargetCamera3D : ICamera3D, IBaseComponent, IDrawable
    {
        public Vector3 Position { get; set; }

        public Vector3 Target { get; set; }

        public bool ShouldDraw { get; set; }

        public Matrix View { get; set; }
        public Matrix Projection { get; set; }

        public string Name { get; set; }

        public BoundingFrustum Frustum { get; set; }
        public bool ShouldSerialize { get; set; }

        public TargetCamera3D()
        {
            NearPlane = 1;
            FarPlane = 1000;

            ShouldDraw = true;
            Frustum = new BoundingFrustum(View * Projection);
            ShouldSerialize = true;
        }
        public TargetCamera3D(GameScreen gs)
        {
            NearPlane = 1;
            FarPlane = 1000;

            ShouldDraw = true;
            gs.AddComponent(this);
            Frustum = new BoundingFrustum(View * Projection);
            ShouldSerialize = true;
        }

        public float AspectRatio = 1;
        public float NearPlane { get; set; }
        public float FarPlane { get; set; }
        public float FieldOfView = MathHelper.ToRadians(45);

        public virtual void Draw()
        {
            Projection = CameraUtil.GetProjectionMatrix(FieldOfView, AspectRatio, NearPlane, FarPlane);
            View = Matrix.CreateLookAt(this.Position, this.Target, Vector3.Up);
            Frustum.Matrix = View * Projection;
        }

        public void SerializeData(SerializationData parentData, int index)
        {
        }

        public void DeserializeData(SerializationData parentData, int index)
        {
        }

    }
}
